<template>
  <div>
    <vxe-grid :id="'single_grid_' + menu.id" ref="table" v-bind="gridOptions" :data="datas" :border="true"
      :export-config="{ remote: true, exportMethod: this.exportDataEvent }" stripe size="mini" :height="height"
      :toolbar-config="tableToolbar" :loading="loading" :custom-config="{ storage: true }" show-overflow
      show-header-overflow resizable keep-source highlight-hover-row highlight-current-row
      :edit-config="{ trigger: 'dblclick', mode: 'row' }"
      :checkbox-config="{ labelField: '', highlight: true, range: true, change: 'checkEvent' }"
      :pager-config="data_object.is_page?tablePage:false" style="width: 100%" :scoped-slots="{ $scopedSlots }" @form-submit="query"
      @checkbox-change="checkEvent" @checkbox-all="checkEvent" @checkbox-range="checkEvent"
      @page-change="handleCurrentChange" @edit-closed="editClosedEvent" @cell-menu="cellContextMenuEvent"
      @cell-click="cellContextMenuEvent" @menu-click="contextMenuClickEvent" :merge-cells="mergeCells">
      <template #loading>
        <div class="first-loading-wrp">
          <div class="loading-wrp" style="padding:20px">
            <span class="dot dot-spin">
              <i></i>
              <i></i>
              <i></i>
              <i></i>
            </span>
          </div>
          <div style="font-size:14px;color:#1890ff;font-weight: bold;">加载中...</div>
        </div>
        <!-- <div><img src="@/assets/theme_images/loading2.gif" style="width: 50px;"></div>
        <div style="font-size:14px;color:black">加载中...</div> -->
      </template>
      <template v-for="(index, name) in $scopedSlots" v-slot:[name]="{ row }">
        <slot :name="name" v-bind="{ row }" />
      </template>
      <template #operate_item>
        <vxe-button size="mini" type="submit" status="primary" content="查询" />
        <vxe-button size="mini" type="reset" content="重置" />
      </template>
      <template #toolbar_buttons>
        <span style="margin-left: 10px;" />
        <slot name="head_btn_prepend" :rows="select_rows"/>
        <el-button v-if="data_object.is_add && (!is_permission || buttonAuth(menu.no + '_' + data_object.no + '_add'))"
          type="primary" size="mini" round @click="addInit">
          新增
        </el-button>
        <template v-for="item in headButtons">
          <el-button v-if="item.is_show && (!is_permission || headButtonAuth(item))" :key="item.id" size="mini" round
            :type="item.color" :icon="item.icon"
            @click="item.type == 1 ? headButtonConfirmClick(item) : item.type == 2 ? headButtonComboboxClick(item) : headButtonDialogClick(item)">
            {{ item.name }}
          </el-button>
        </template>
        <slot name="head_btn_append" :rows="select_rows" />
        <el-upload v-if="data_object.is_import" style="margin-left:10px"
          :action="action"
          :show-file-list="false"
          :on-success="handleSuccess"
          :data="{'data_object_no':data_object.no}"
          :headers="{'Palmdoit-Token':token}">
          <el-button size="mini" type="primary" round>导入</el-button>
        </el-upload>
      </template>
      <template #operate="{ row }">
        <slot name="line_btn_prepend" :row="row" />
        <template v-for="item in lineButtons">
          <el-button v-if="item.is_show && (!is_permission || lineButtonAuth(item, row))" :key="item.id" size="mini"
            round :type="item.color" :icon="item.icon" @click="
              item.type == 1
                ? lineButtonConfirmClick(row, item)
                : item.type == 2
                  ? lineButtonComboboxClick(row, item)
                  : item.type == 3
                    ? lineButtonDialogClick(row, item)
                    : lineButtonTabClick(row, item)
            ">
            {{ item.name }}
          </el-button>
        </template>
        <slot name="line_btn_append" :row="row" />
        <el-button
          v-if="data_object.is_update && (!is_permission || buttonAuth(menu.no + '_' + data_object.no + '_edit'))"
          size="mini" icon="el-icon-edit" circle @click="editInit(row)" />
        <el-button
          v-if="data_object.is_delete && (!is_permission || buttonAuth(menu.no + '_' + data_object.no + '_del'))"
          type="danger" size="mini" icon="el-icon-delete" circle @click="del(row)" />
      </template>
    </vxe-grid>
    <vxe-modal ref="coderModel" v-model="coder" width="100%" title="编辑元数据">
      <div>
        <el-descriptions title="菜单信息" :column="3" size="mini" border>
          <template slot="extra">
            <el-button type="success" size="small" @click="close">关闭并刷新菜单</el-button>
          </template>
          <el-descriptions-item>
            <template slot="label">
              菜单编号
            </template>
            {{ menu.no }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              菜单名称
            </template>
            {{ menu.title }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              元对象
            </template>
            {{ menu.data_object_no }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              子元对象
            </template>
            {{ menu.son_data_object_no }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              路径
            </template>
            {{ menu.path }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              组件
            </template>
            {{ menu.component }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <Object ref="object" :data_object_no="data_object_no" :table_height="115" />
      <FieldAndButton ref="fab" :data_object_no="data_object_no" :table-height="500" :objects="[]" />
    </vxe-modal>
    <!-- 新增dialog -->
    <AddForm ref="addDialog" @success="newSuccess" @show="addShow">
      <template #add_form_append={form}>
        <slot name="form_append" :form="form" statu="add"/>
      </template>
    </AddForm>
    <!-- 新增dialog -->
    <!-- 编辑dialog -->
    <EditForm ref="editDialog" :editFormConfirm="editFormConfirm" @success="editSuccess" @show="editShow">
      <template #edit_form_append={form}>
        <slot name="form_append" :form="form" statu="edit"/>
      </template>
    </EditForm>
    <!-- 编辑dialog -->
    <!-- 文件dialog -->
    <File ref="fileList" @fileModify="fileModify" />
    <!-- 文件dialog -->
    <!-- dialog -->
    <ButtonDialog ref="buttonDialog" />
    <!-- dialog -->
  </div>
</template>

<script>
  import XEClipboard from 'xe-clipboard'
  import * as api from '@/api/template/index'
  import * as commonApi from '@/api/template/common'
  import {baseURL} from '@/config'
  import AddForm from '@/views/template/components/addForm.vue'
  import EditForm from '@/views/template/components/editForm.vue'
  import File from '@/views/template/components/file.vue'
  import ButtonDialog from '@/views/template/components/buttonDialog.vue'
  import Object from '@/views/coder/components/object'
  import FieldAndButton from '@/views/coder/components/fieldAndButton'
  import Bus from '@/utils/bus.js'
  import store from '@/store'

  import {
    mapGetters
  } from 'vuex'

  export default {
    computed: {
      ...mapGetters({
        userinfo: 'user/userinfo'
      })
    },
    name: 'RayTable',
    components: {
      AddForm,
      EditForm,
      File,
      ButtonDialog,
      Object,
      FieldAndButton
    },
    props: {
      menu: {
        type: Object,
        default: () => {}
      }, // 菜单信息 作用于鉴权
      data_object_no: {
        type: String
      }, // 元对象信息
      custom_columns: {
        type: Array,
        default: () => []
      }, // 自定义列
      right_menu: {
        type: Object,
        default: () => {}
      }, // 自定义右键菜单
      height: {
        type: Number
      }, // 表格高度
      precondition: {
        type: Object,
        default: () => {}
      }, // 查询前置条件
      other_data: {
        type: Object,
        default: () => {}
      }, // 其他数据
      is_permission: {
        type: Boolean,
        default: true
      }, // 是否鉴权
      auto_load: {
        type: Boolean,
        default: true
      }, // 是否自动加载
      editFormConfirm: {
        type: Boolean,
        default: true
      }, // 编辑框是否可以提交
      footer_method: {
        type: Function,
        default: function() {
          return []
        }
      } // 尾部数据方法
    },
    data() {
      return {
        token:store.getters['user/token'],
        action:baseURL+'/common/importData',
        gridOptions: {
          columns: [{
            type: 'checkbox',
            title: '',
            width: 40
          }],
          formConfig: {
            data: {},
            items: []
          },
          showFooter: true,
          footerMethod: this.footer_method,
          menuConfig: {
            header: {
              options: []
            },
            body: {
              options: [
                [{
                    code: 'copyCell',
                    name: '复制当前内容',
                    prefixIcon: 'vxe-icon-copy',
                    visible: true,
                    disabled: false
                  },
                  {
                    code: 'copyRow',
                    name: '复制整行内容',
                    prefixIcon: 'vxe-icon-copy',
                    visible: true,
                    disabled: false
                  }
                ]
              ]
            }
          },
          loadingConfig: {
            icon: 'vxe-icon-indicator roll',
            text: '正在拼命加载中...'
          }
        },
        data_object: {},
        datas: [],
        columns: [],
        selectDatas: {},
        formLabelWidth: '120px',
        tablePage: {
          currentPage: 1,
          pageSize: 20,
          total: 0,
          pageSizes: [20, 50, 100, 200, 500],
          layouts: ['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total'],
          perfect: true
        },
        exportConfig: {
          remote: true,
          exportMethod: this.exportDataEvent
        },
        select_rows: [],
        rules: {},
        headButtons: [],
        lineButtons: [],
        tableToolbar: {
          slots: {
            buttons: 'toolbar_buttons'
          },
          refresh: true,
          export: true,
          print: true,
          zoom: true,
          custom: true,
          perfect: true
        },
        dialogRow: {},
        edit_row: {},
        select_e: {},
        menuVisible: false,
        loading: false,
        interceptorConfirm: false,
        coder: false,
        mergeCells:[]
      }
    },
    watch: {
      columns: function() {
        this.$nextTick(() => {
          if (this.auto_load) {
            this.getData()
          }
        })
      }
    },
    created() {
      this.getColumns()
    },
    methods: {
      getColumns: function(event) {
        api.getColumns(this.data_object_no).then(res => {
          this.selectDatas = res.selectDatas
          this.rules = res.validator
          this.headButtons = res.headButtons
          this.lineButtons = res.lineButtons
          this.data_object = res.data_object
          this.tablePage.pageSize = res.data_object.page_size
          // 初始化列
          this.generateColumns(this.gridOptions.columns, res.list, this.custom_columns)
          // 初始化查询
          if (this.data_object.is_query) {
            this.generateQuery(this.gridOptions.formConfig, res.list)
          }
          // 初始化右键菜单
          this.generateRightMenu()
          this.columns = res.list
        })
      },
      // 格式化列
      generateColumns(option, columns, custom_columns) {
        custom_columns.sort(function(a, b) {
          return a.order_num - b.order_num
        })
        columns.forEach((item, index) => {
          for (var i = 0; i < custom_columns.length; i++) {
            if (custom_columns[0].order_num <= item.order_num) {
              option.push(custom_columns[0])
              custom_columns.splice(0, 1)
            } else {
              break
            }
          }
          var column = {}
          column.visible = item.is_show
          column.field = item.en
          column.title = item.cn
          column.width = item.width
          column.align = item.align
          column.headerAlign = 'center'
          column.sortable = item.is_order
          if (item.type === 'selector' || item.type === 'user') {
            column.cellRender = {
              name: 'CellSelector',
              props: {
                is_formatter: JSON.parse(item.type_config).is_formatter
              }
            }
          } else if (item.type === 'file') {
            column.cellRender = {
              name: '$button',
              props: {
                status: 'primary',
                size: 'small',
                content: '查看',
                itemInfo: item,
                round: true
              },
              events: {
                click: this.fileShow
              }
            }
          } else if (item.is_line_update && this.data_object.is_line_update) {
            if (item.type === 'input') {
              column.editRender = {
                name: 'EditDownTextarea'
              }
            } else if (item.type === 'select' || item.type === 'radio') {
              column.editRender = {
                name: '$select',
                options: this.selectDatas[item.en],
                optionProps: {
                  value: 'value',
                  label: 'label'
                }
              }
            } else if (item.type === 'switch') {
              column.cellRender = {
                name: '$switch',
                events: {
                  change: this.editClosedEvent
                }
              }
            } else if (item.type === 'date') {
              column.editRender = {
                name: '$input',
                props: {
                  type: 'date'
                }
              }
            } else if (item.type === 'datetime') {
              column.editRender = {
                name: '$input',
                props: {
                  type: 'datetime'
                }
              }
            }
          } else if (item.formatter) {
            column.formatter = ['format', item.formatter]
            column.type = 'html'
          } else if (item.type === 'select' || item.type === 'radio') {
            column.cellRender = {
              name: 'cell-select',
              options: this.selectDatas[item.en]
            }
          } else if (item.type === 'switch') {
            column.cellRender = {
              name: 'cell-switch'
            }
          }
          option.push(column)
        })
        for (var i = 0; i < custom_columns.length; i++) {
          option.push(custom_columns[i])
        }
        if (this.data_object.is_handle) {
          var handleColumn = {
            title: '操作',
            slots: {
              default: 'operate'
            },
            width: this.data_object.handle_width,
            showOverflow: true,
            showHeaderOverflow: true,
            fixed: 'right'
          }
          option.push(handleColumn)
        }
      },
      // 格式化查询条件
      generateQuery(formConfig, columns) {
        var num = 1
        var folding = false
        columns.forEach((item, index) => {
          if (item.is_query) {
            if (num > 4) {
              folding = true
            }
            this.$set(formConfig.data, [item.en], '')
            if (item.type === 'input') {
              formConfig.items.push({
                field: item.en,
                span: 6,
                folding: folding,
                title: item.cn,
                itemRender: {
                  name: '$input'
                }
              })
            } else if (item.type === 'select') {
              formConfig.items.push({
                field: item.en,
                span: 6,
                folding: folding,
                title: item.cn,
                itemRender: {
                  name: 'ElSelect',
                  options: this.selectDatas[item.en],
                  props: {
                    placeholder: '请选择'
                  }
                }
              })
            } else if (item.type === 'date') {
              formConfig.items.push({
                field: item.en,
                span: 6,
                folding: folding,
                title: item.cn,
                itemRender: {
                  name: 'ElDatePicker',
                  props: {
                    type: 'daterange',
                    'value-format': 'yyyy-MM-dd',
                    'start-placeholder': '开始日期',
                    'end-placeholder': '结束日期'
                  }
                }
              })
            } else if (item.type === 'datetime') {
              formConfig.items.push({
                field: item.en,
                span: 6,
                folding: folding,
                title: item.cn,
                itemRender: {
                  name: 'ElDatePicker',
                  props: {
                    type: 'datetimerange',
                    'value-format': 'yyyy-MM-dd HH:mm:ss',
                    'start-placeholder': '开始时间',
                    'end-placeholder': '结束时间'
                  }
                }
              })
            } else if (item.type === 'selector') {
              formConfig.items.push({
                field: item.en,
                span: 6,
                folding: folding,
                title: item.cn,
                itemRender: {
                  name: 'FormSelector',
                  props: {
                    item: item
                  }
                }
              })
            }
            num = num + 1
          }
        })
        formConfig.items.push({
          span: 24,
          align: 'center',
          collapseNode: folding,
          slots: {
            default: 'operate_item'
          }
        })
      },
      /**
       * 生成自定义右键菜单
       */
      generateRightMenu() {
        if (this.right_menu != null) {
          if (this.right_menu.header != null) {
            this.gridOptions.menuConfig.header.options = this.gridOptions.menuConfig.header.options.concat(this
              .right_menu.header.options)
          }
          if (this.right_menu.body != null) {
            this.gridOptions.menuConfig.body.options = this.gridOptions.menuConfig.body.options.concat(this.right_menu
              .body.options)
          }
        }
        if (this.userinfo.is_coder) {
          this.gridOptions.menuConfig.header.options.unshift([{
            code: 'dataObject',
            name: '编辑元数据',
            prefixIcon: 'el-icon-setting',
            visible: true
          }])
        }
      },
      /**
       * 获取表格数据
       */
      getData: function(event) {
        this.loading = true
        var queryForm = JSON.parse(JSON.stringify(this.gridOptions.formConfig.data))
        for (const key in this.precondition) {
          this.$set(queryForm, key, this.precondition[key])
        }
        api.getData(this.data_object_no, queryForm, this.tablePage.currentPage, this.tablePage.pageSize)
          .then(res => {
            this.datas = res.list
            this.tablePage.total = res.totalResult
            this.mergeCells = res.mergeCells
          })
          .finally(e => {
            this.loading = false
          })
      },
      /**
       * 分页切换页码
       */
      handleCurrentChange: function({
        currentPage,
        pageSize
      }) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.getData()
      },
      /**
       * 从第一页查询
       */
      query() {
        this.tablePage.currentPage = 1
        this.getData()
      },
      /**
       * 新增前
       */
      addInit: function() {
        var param = {}
        param.id = this.menu.id
        param.columns = this.columns
        param.selectDatas = this.selectDatas
        param.rules = this.rules
        param.precondition = this.precondition
        param.other_data = this.other_data
        param.data_object = this.data_object
        this.$refs.addDialog.show(param)
      },
      /**
       * 新增成功后
       * @param {Object} newData 新增成功的数据
       */
      async newSuccess(newData) {
        const $table = this.$refs.table
        const {
          row
        } = await $table.insert(newData)
        await $table.setCurrentRow(row)
      },
      /**
       * 修改前
       * @param {Object} row 修改前的行数据
       */
      editInit: function(row) {
        this.select_row = JSON.parse(JSON.stringify(row))
        var param = {}
        param.id = this.menu.id
        param.columns = this.columns
        param.selectDatas = this.selectDatas
        param.rules = this.rules
        param.form = this.select_row
        param.precondition = this.precondition
        param.other_data = this.other_data
        param.data_object = this.data_object
        this.$refs.editDialog.show(param)
      },
      /**
       * 修改成功后
       * @param {Object} row 修改后的行数据
       */
      editSuccess(row) {
        this.$refs.table.reloadRow(this.select_row, row, '')
      },
      /**
       * 行内修改
       */
      editClosedEvent({
        row,
        column
      }, event) {
        this.loading = true
        api.edit_({
          row: row,
          data_object_no: this.data_object_no,
          column: column.property,
          type: 'cell'
        }).then(res => {
          this.$message({
            message: res.msg,
            type: 'success'
          })
          this.$refs.table.reloadRow(row, null, column.property)
        }).catch(res => {
          this.$refs.table.revertData()
        }).finally(e => {
          this.loading = false
        })
      },
      /**
       * 删除行
       * @param {Object} row 删除的行数据
       */
      del: function(row) {
        this.$confirm('确定要删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          api.del_(row.id, this.data_object_no).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.$refs.table.remove(row)
          }).finally(e => {
            this.loading = false
          })
        })
      },
      /**
       * 导出数据
       */
      exportDataEvent: function({
        options
      }) {
        const body = {
          filename: options.filename,
          sheetName: options.sheetName,
          isHeader: options.isHeader,
          original: options.original,
          mode: options.mode,
          ids: options.mode === 'selected' ? options.data.map(item => item.id) : [],
          fields: options.columns.map(column => {
            return {
              field: column.property,
              title: column.title
            }
          })
        }
        // 开始服务端导出
        commonApi.export_({
            body: body,
            queryForm: this.gridOptions.formConfig.data,
            parent_value: this.parent_id,
            parent_key: this.parent_id_field,
            data_object_no: this.data_object_no
          })
          .then(res => {
            location.href = res.url
          }).finally(e => {
            this.loading = false
          })
      },
      /**
       * 导入数据回调
       */
      handleSuccess(res) {
        this.$message({
          message: res.msg,
          type: res.state=='ok'?'success':'error'
        })
        if(res.state=='ok'){
          this.getData()
        }
      },
      /**
       * 查看文件控件
       */
      fileShow({
        row,
        column
      }) {
        var file_edit = true
        var itemInfo = column.cellRender.props.itemInfo
        this.fileItemInfo = itemInfo
        if (itemInfo.update_validate != null) {
          var auth = JSON.parse(itemInfo.update_validate)
          for (var j = 0; j < auth.length; j++) {
            for (const key in this.row) {
              if (key === auth[j].field) {
                var aaa = this.row[key] + auth[j].operator + auth[j].value
                if (!eval(aaa)) {
                  file_edit = false
                }
              }
            }
          }
        }
        this.select_row = row
        this.column = column
        this.$refs.fileList.show({
          ids: row[column.property],
          title: itemInfo.cn + '列表',
          accpetTypes: itemInfo.type_config.split('|')[2],
          limit: itemInfo.type_config.split('|')[1],
          folder: itemInfo.type_config.split('|')[0],
          file_edit: column.cellRender.props.itemInfo.is_line_update && this.data_object.is_line_update && file_edit
        })
      },
      /**
       * 文件列表修改
       * @param {Object} fileIds 修改后的id集
       */
      fileModify(fileIds) {
        this.loading = true
        this.select_row[this.column.property] = fileIds
        api.edit_({
          row: this.select_row,
          data_object_no: this.data_object_no,
          column: this.column.property,
          type: 'cell'
        }).then(res => {
          this.$message({
            message: res.msg,
            type: 'success'
          })
          this.$refs.table.reloadRow(this.select_row, null, this.column.property)
        }).finally(e => {
          this.loading = false
        })
      },
      lineButtonConfirmClick(row, button) {
        row.other_data = this.other_data
        this.$confirm(button.tip, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          api.post_(button.action, row).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.getData()
          }).finally(e => {
            this.loading = false
          })
        })
      },
      lineButtonComboboxClick(row, button) {
        row.other_data = this.other_data
        this.$prompt(button.tip, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({
          value
        }) => {
          row.comboValue = value
          this.loading = true
          api.post_(button.action, row).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.getData()
          }).finally(e => {
            this.loading = false
          })
        })
      },
      lineButtonDialogClick(row, button) {
        this.select_row = row
        row.other_data = this.other_data
        this.$refs.buttonDialog.show(button, row)
      },
      headButtonConfirmClick(button) {
        this.$confirm(button.tip, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          api.post_(button.action, {
            rows: this.select_rows,
            other_data: this.other_data
          }).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.getData()
          }).finally(e => {
            this.loading = false
          })
        })
      },
      headButtonComboboxClick(button) {
        this.$prompt(button.tip, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({
          value
        }) => {
          this.loading = true
          api.post_(button.action, {
            rows: this.select_rows,
            comboValue: value,
            other_data: this.other_data
          }).then(res => {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.getData()
          }).finally(e => {
            this.loading = false
          })
        })
      },
      headButtonDialogClick(button) {
        this.$refs.buttonDialog.show(button, {}, this.select_rows, this.other_data)
      },
      checkEvent({
        checked,
        records
      }) {
        this.select_rows = records
      },
      buttonAuth: function(permission_no) {
        if (this.userinfo.permissions.indexOf(permission_no) !== -1) {
          return true
        }
        return false
      },
      headButtonAuth: function(item) {
        if (this.userinfo.permissions.indexOf(this.menu.no + '_' + item.permission_no) === -1) {
          return false
        }
        if (item.auth_role != null) {
          var roles = item.auth_role.split(',')
          for (var i = 0; i < roles.length; i++) {
            if (this.userinfo.roles.indexOf(roles[i]) !== -1) {
              return true
            }
          }
          return false
        } else {
          return true
        }
      },
      lineButtonAuth: function(item, row) {
        if (this.userinfo.permissions.indexOf(this.menu.no + '_' + item.permission_no) === -1) {
          return false
        }
        if (item.auth_role != null) {
          var roles = item.auth_role.split(',')
          for (var i = 0; i < roles.length; i++) {
            if (this.userinfo.roles.indexOf(roles[i]) !== -1) {
              if (item.auth_row != null) {
                var authrow = JSON.parse(item.auth_row)
                for (var j = 0; j < authrow.length; j++) {
                  for (const key in row) {
                    if (key === authrow[j].field) {
                      var aaa = row[key] + authrow[j].operator + authrow[j].value
                      if (!eval(aaa)) {
                        return false
                      }
                    }
                  }
                }
              }
              return true
            }
          }
        } else {
          if (item.auth_row != null) {
            var authrow1 = JSON.parse(item.auth_row)
            for (var k = 0; k < authrow1.length; k++) {
              for (const key in row) {
                if (key === authrow1[k].field) {
                  var aaaa = row[key] + authrow1[k].operator + authrow1[k].value
                  if (!eval(aaaa)) {
                    return false
                  }
                }
              }
            }
          }
          return true
        }
        return false
      },
      cellContextMenuEvent({
        row
      }) {
        this.select_row = row
        this.$refs.table.setCurrentRow(row)
        this.$emit('ray-table-cell-click', row)
      },
      contextMenuClickEvent({
        menu,
        row,
        column,
        type
      }) {
        if (menu.code === 'dataObject') {
          this.coder = true
        } else if (menu.code === 'copyCell' && row && column) {
          if (XEClipboard.copy(row[column.property])) {
            this.$message({
              message: '已复制单元格内容到剪贴板！',
              type: 'success'
            })
          }
        } else if (menu.code === 'copyRow' && row && column) {
          var copyRow
          for (const key in row) {
            copyRow += row[key] + ','
          }
          if (XEClipboard.copy(copyRow)) {
            this.$message({
              message: '已复制整行内容到剪贴板！',
              type: 'success'
            })
          }
        } else {
          this.$emit('menu_click_event', {
            menu: menu,
            row: row,
            column: column,
            type: type
          })
        }
      },
      close() {
        this.coder = false
        Bus.$emit('removeCache', 'closeSelectedTag', this.$route.path)
        this.$baseEventBus.$emit('reload-router-view')
      }
    }
  }
</script>

<style></style>
